package com.projectpractice.repository;

import com.projectpractice.bean.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author TangLuJie
 * @date 2020/6/30 20:13
 */
public interface UserRepository extends JpaRepository<User,Integer> {

    public User getUserByName(String userName);

    public User getUserById(Integer userId);

    @Transactional
    @Modifying
    @Query(value = "update user set name = :name, headpic = :headpic, password = :password, sex = :sex, email = :email, role = :role where id = :id",nativeQuery = true)
    public void updateById(@Param("id") Integer id, @Param("name") String name,@Param("headpic") String headpic,
                           @Param("password") String password,@Param("sex") String sex,
                           @Param("email") String email,@Param("role") String role);
}
